<?php
require_once(dirname(__FILE__) . '/include/config.inc.php');

$time=time();

$cat_arr=[
    '12'=>'25',
    '13'=>'26',
    '14'=>'27',
    '15'=>'44',
    '16'=>'28',
    '38'=>'29',
    '39'=>'30',
    '17'=>'35',
    '18'=>'34',
    '19'=>'33',
    '20'=>'32',
    '21'=>'36',
    '22'=>'37',
    '23'=>'38',
    '32'=>'39',
    '33'=>'40',
    '34'=>'41',
    '35'=>'42',
    '30'=>'43',
    '27'=>'6',
    '28'=>'5',
    '29'=>'8',
];


$dosql->Execute("SELECT a.*,p.content FROM  `web_news`  as a left join `web_news_data` as p on p.id=a.id  WHERE  1   ORDER BY a.id asc", 8);
while ($row3 = $dosql->GetArray(8)) {

    $id = $row3['id'];
    echo $id . "<br>";
    $content = addslashes($row3['content']);
    $title = $row3['title'];
    $image = $row3['thumb'];
    $keywords = $row3['keywords'];
    $keywords_arr=explode(" ",$keywords);
    $keywords=implode(",",$keywords_arr);
    $description = $row3['description'];
    $catid = $row3['catid'];

    $channel_id=0;
    if(array_key_exists($catid,$cat_arr)){
        $channel_id=$cat_arr[$catid];
    }



    $dosql->Execute("insert into `web_cms_archives`(channel_id,model_id,title,image,keywords,description,createtime,updatetime,publishtime,status) values ('$channel_id','1','$title','$image','$keywords','$description','$time','$time','$time','normal')");
    $lastid = $dosql->GetLastID();
    $dosql->ExecNoneQuery("insert into `web_cms_addonnews`(`id`,`content`) values ('$lastid','$content')");


}


foreach ($arr as $key => $val) {

    echo $key;
    var_dump($val);


    $dddd=$val['author'];
    arsort($dddd);



    foreach ($dddd as $k => $v) {


        $title = $v['zname'];
        $tbid=$v['authorid'];
        $content = "";
        $time = time();

        $channel_id = $key + 2;

        $dosql->Execute("insert into `fa_cms_archives`(channel_id,model_id,title,image,createtime,updatetime,publishtime,status,tbid) values ('$channel_id','2','$title','','$time','$time','$time','normal','$tbid')");
        $lastid = $dosql->GetLastID();
        $dosql->ExecNoneQuery("insert into `fa_cms_addonmingjia`(`id`,`content`) values ('$lastid','$content')");


        echo $title . "添加成功" . "<br>";
    }

}


/*
 * 获取一个远程图片
 *
 * @access  public
 * @param   $url       string  获取字段所属模型
 * @return  $save_url  string  返回上传后地址
*/
function GetRemPic($url)
{

    $filename_arr = parse_url($url);
    $path = $filename_arr['path'];
    $filename_arr = explode('/', $path);
    $filename = array_pop($filename_arr);

    $upload_url = '/uploads/image/news/';
    $upload_dir = PHPMYWIND_UPLOAD . "/images/news/";

    //上传文件路径
    $save_url = $upload_url . $filename;
    $save_dir = $upload_dir . $filename;
    echo "保存路径" . $save_dir . "<br/>";

    if (file_exists($save_dir)) {
        return $save_url;
    }


    //引入下载类
    require_once(PHPMYWIND_DATA . '/httpfile/down.class.php');

    //初始化变量
    $htd = new HttpDown();
    $htd->OpenUrl($url);


    //判断文件类型
    $sparr = array('image/pjpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/xpng', 'image/wbmp');
    if (!in_array($htd->GetHead("content-type"), $sparr)) {
        return FALSE;
    } else {
        $type = $htd->GetHead("content-type");

        if ($type == 'image/gif')
            $tempfile_ext = 'gif';

        else if ($type == 'image/png')
            $tempfile_ext = 'png';

        else if ($type == 'image/wbmp')
            $tempfile_ext = 'bmp';

        else
            $tempfile_ext = 'jpg';


        echo "保存";

        $rs = $htd->SaveToBin($save_dir);
    }

    $htd->Close();
    return ($rs ? $save_url : '');
}


?>